package com.globalwave.system.vo
{
    import mx.collections.ArrayCollection;
  
    public class User
    {
        public var user_id : int  ;
        public var login_id : String ;
        public var password_ : String ;
        public var name_ : String ;
        public var email_ : String ;
        //private String region_ ;
        public var status_ : String ;
        public var desc_ : String ;
		
		
		public var shop_code:String = null;
		public var shop_name:String = null ;
		public var system_date:String = null ;
		public var sale_date:String = null ;
		public var terminal_code:String = null ;
		
        
        public var privilegeIds : ArrayCollection ;
            
        public const isValidatePrivilege : Boolean = true ;
        
		private static var instance:User ;
		
		public static function getCurrentUser():User {
			return instance ;
		}
		
		public static function setCurrentUser(userAsXml:XML):void {
			new User(userAsXml);
		}
		
		public function User(userAsXml:XML=null) {
			this.privilegeIds = new ArrayCollection() ;
			
			if (userAsXml != null) {
				this.user_id = userAsXml.user_id ;
				this.login_id = userAsXml.User.login_id ;
				this.name_ = userAsXml.User.name_ ;
				
				var ids : XML = userAsXml.privilege_ids[0] ;
				
				for (var i : int = ids.children().length() - 1 ; i >= 0 ; i --) {
					this.privilegeIds.addItem(int(ids.e[i].valueOf())) ;
				}
			}
			
			instance = this ;
		}
            
        public function hasPrivilege(pid : Object) : Boolean {
            if (!isValidatePrivilege || pid == null || pid == "" || int(pid) == -1) {
                return true ;
            }
            
            return this.privilegeIds.contains(int(pid)) ;
        }    
    }
}